package com.hyy.cn.codeget;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @Author Ronghao.Guo
 * @Date 2023/6/17 11:31
 */
public class CodeGet {

    public static void main(String[] args) {
        //1.创建代码生成器
        AutoGenerator mpg = new AutoGenerator();
        //2.全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("D:\\IDEA Project\\CodeGet\\src\\main\\java");  //生成代码存放位置
        gc.setServiceName("%sService");
        gc.setAuthor("huyaoying");
        gc.setOpen(false);
        mpg.setGlobalConfig(gc);

        //3.配置数据源
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/mysql_test?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        //4.包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.hyy.cn.codeget");
        pc.setModuleName("sys");   //模块名
        pc.setController("controller");
        pc.setService("service");
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);

        //5.策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setInclude("ngtc_attachment", "ngtc_cert", "ngtc_cert_batch");    //表名
        strategyConfig.setNaming(NamingStrategy.underline_to_camel); // 数据库表映射到实体
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);  //数据库表字段映射到属性
        strategyConfig.setEntityLombokModel(true);  //
        strategyConfig.setRestControllerStyle(true);  //restful  api风格控制器
        strategyConfig.setControllerMappingHyphenStyle(true);  //url 中驼峰转连字符
        mpg.setStrategy(strategyConfig);

        //6.执行
        mpg.execute();

    }
}